package com.campus.common.config;


import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author PanBangLin
 * @version 1.0
 * @date 2022/6/18 16:30
 */
@Configuration
public class ElasticsearchConfiguration {
    @Bean
    public ElasticsearchClient esClient(){
        // 创建ES客户端部分
        RestClient restClient = RestClient.builder(
                new HttpHost("43.138.211.99", 9200)).build();
        ElasticsearchTransport transport = new RestClientTransport(
                restClient, new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);
    }

}

